package com.xd.study.fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xd.study.R;

/**
 * Created by DGF on 2015/4/24.
 */
public class LifecycleFragment2 extends Fragment {

    /**
     * 每次创建都会绘制Fragment的View组件时调用
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //return super.onCreateView(inflater, container, savedInstanceState);

        View view = inflater.inflate(R.layout.fragment, container, false);
        TextView textView = (TextView)view.findViewById(R.id.fragment_textview);
        textView.setText("第二个fragment");

        Log.i("Fragment", "Fragment2 -- onCreateView");

        return view;
    }

    /**
     * Fragment被添加到Activity时调用，仅调用一次
     * @param activity
     */
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        Log.i("Fragment", "Fragment2 -- onAttach");
    }

    /**
     * 创建Fragment时调用，仅调用一次
     * @param savedInstanceState
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("Fragment", "Fragment2 -- onCreate");
    }

    /**
     * 当Fragment所在的Activity启动完成时调用
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.i("Fragment", "Fragment2 -- onActivityCreated");
    }

    /**
     * 启动Fragment
     */
    @Override
    public void onStart() {
        super.onStart();
        Log.i("Fragment", "Fragment2 -- onStart");
    }

    /**
     * 恢复Fragment时回调，如果已经调用了onStart方法，后面一定会调用onResume方法
     */
    @Override
    public void onResume() {
        super.onResume();
        Log.i("Fragment", "Fragment2 -- onResume");
    }

    /**
     * 暂停Fragment，
     */
    @Override
    public void onPause() {
        super.onPause();
        Log.i("Fragment", "Fragment2 -- onPause");
    }

    /**
     * 停止Fragment
     */
    @Override
    public void onStop() {
        super.onStop();
        Log.i("Fragment", "Fragment2 -- onStop");
    }

    /**
     * 销毁Fragment所包含的View的组件时调用
     */
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.i("Fragment", "Fragment2 -- onDestroyView");
    }

    /**
     * 销毁Fragment时调用
     */
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("Fragment", "Fragment2 -- onDestroy");
    }

    /**
     * Fragment从Activity中删除时调用，仅调用一次
     */
    @Override
    public void onDetach() {
        super.onDetach();
        Log.i("Fragment", "Fragment2 -- onDetach");
    }
}
